package com.ww.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 比较工具类
 * @author wangwei
 *
 */
public class CompareUtils {
	
	/**
	 * find str in list1 not in list2
	 * @param list1
	 * @param list2
	 * @return
	 */
	public static List<String> diffStrInList1(List<String> list1, List<String> list2){
		List<String> diffList = new ArrayList<String>();
		for(String str1:list1){
			boolean flag = false;
			for(String str2:list2){
				if(str1.equals(str2)){
					flag = true;
					continue;
				}
			}
			if(!flag){
				diffList.add(str1);
			}
		}
		return diffList;
	}
	
	/**
	 * count str in the list > 1
	 * @param list
	 * @return
	 */
	public static Map<String, Integer> countSameStr(List<String> list){
		Map<String, Integer> sameMap = new HashMap<String, Integer>();
		for(String str:list){
			int count = 0;
			for(String tmpStr:list){
				if(str.equals(tmpStr)){
					count++;
					if(count > 1){
						sameMap.put(str, count);
					}
				}
			}
		}
		return sameMap;
	}
}
